package com.spic.business.accident.interevents.classreport.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import com.spic.business.accident.interevents.classreport.domain.InternalEventInspectionReport;
import com.spic.business.accident.interevents.classreport.service.IInternalEventInspectionReportService;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.page.TableDataInfo;

/**
 * 内部事件班组自查报告Controller
 *
 * @author 任翔
 * @date 2021-12-01
 */
@RestController
@RequestMapping("/accident/report")
public class InternalEventInspectionReportController extends BaseController {
    @Autowired
    private IInternalEventInspectionReportService internalEventInspectionReportService;

    /**
     * 查询内部事件班组自查报告列表
     */
    @PreAuthorize(hasPermi = "business:classReport:list")
    @GetMapping("/list")
    public TableDataInfo list(InternalEventInspectionReport internalEventInspectionReport) {
        startPage();
        List<InternalEventInspectionReport> list = internalEventInspectionReportService.selectInternalEventInspectionReportList(internalEventInspectionReport);
        return getDataTable(list);
    }

    /**
     * 导出内部事件班组自查报告列表
     */
    @PreAuthorize(hasPermi = "business:classReport:export")
    @Log(title = "内部事件班组自查报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InternalEventInspectionReport internalEventInspectionReport) throws IOException {
        List<InternalEventInspectionReport> list = internalEventInspectionReportService.selectInternalEventInspectionReportList(internalEventInspectionReport);
        ExcelUtil<InternalEventInspectionReport> util = new ExcelUtil<InternalEventInspectionReport>(InternalEventInspectionReport.class);
        util.exportExcel(response, list, "内部事件班组自查报告数据");
    }

    /**
     * 获取内部事件班组自查报告详细信息
     */
    @PreAuthorize(hasPermi = "business:classReport:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(internalEventInspectionReportService.selectInternalEventInspectionReportById(id));
    }

    /**
     * 新增内部事件班组自查报告
     */
    @PreAuthorize(hasPermi = "business:classReport:add")
    @Log(title = "内部事件班组自查报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InternalEventInspectionReport internalEventInspectionReport) {
        return toAjax(internalEventInspectionReportService.insertInternalEventInspectionReport(internalEventInspectionReport));
    }

    /**
     * 修改内部事件班组自查报告
     */
    @PreAuthorize(hasPermi = "business:classReport:edit")
    @Log(title = "内部事件班组自查报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InternalEventInspectionReport internalEventInspectionReport) {
        return toAjax(internalEventInspectionReportService.updateInternalEventInspectionReport(internalEventInspectionReport));
    }

    /**
     * 删除内部事件班组自查报告
     */
    @PreAuthorize(hasPermi = "business:classReport:remove")
    @Log(title = "内部事件班组自查报告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(internalEventInspectionReportService.deleteInternalEventInspectionReportByIds(ids));
    }
}
